package dbops

import (
	"database/sql"
	"fmt"
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/goutils/dbutils"
	"strconv"
	"time"
)

type ContractBean struct {
	Id         string           `json:"id"`
	ParentId   string           `json:"parent_id"`
	Htlx       string           `json:"htlx"`
	Xmmc       string           `json:"xmmc"`
	No         string           `json:"no"`
	Wtdw       string           `json:"wtdw"`
	Fzr        string           `json:"fzr"`
	Jbgk       string           `json:"jbgk"`
	Sf         string           `json:"sf"`
	Dq         string           `json:"dq"`
	Bz         string           `json:"bz"`
	Zxdw       string           `json:"zxdw"`
	Tze        string           `json:"tze"`
	Zxqk       string           `json:"zxqk"`
	Htje       string           `json:"htje"`
	Xz         string           `json:"xz"`
	Gznr       string           `json:"gznr"`
	Wcqk       string           `json:"wcqk"`
	Sbqk       string           `json:"sbqk"`
	Xxf        string           `json:"xxf"`
	Wcrq       string           `json:"wcrq"`
	Qsrq       string           `json:"qsrq"`
	Qdrq       string           `json:"qdrq"`
	Djrq       string           `json:"djrq"`
	Htfj       string           `json:"htfj"`
	Jsje       string           `json:"jsje"`
	Additional []AdditionalBean `json:"additional"`
}
type AdditionalBean struct {
	Id         string `json:"id"`
	ContractId string `json:"contract_id"`
	Lx         string `json:"lx"`
	Jbr        string `json:"jbr"`
	Nr         string `json:"nr"`
	Fsrq       string `json:"fsrq"`
	Htmc       string `json:"htmc"`
	Wxdw       string `json:"wxdw"`
	Fpje       string `json:"fpje"`
	Htfj       string `json:"htfj"`
	Htfl       string `json:"htfl"`
	Htnr       string `json:"htnr"`
}

func NewAdditionalBean(data map[string]string) AdditionalBean {
	return AdditionalBean{
		Id:         data["id"],
		ContractId: data["contract_id"],
		Lx:         data["lx"],
		Jbr:        data["jbr"],
		Nr:         data["nr"],
		Fsrq:       data["fsrq"],
		Htmc:       data["htmc"],
		Wxdw:       data["wxdw"],
		Fpje:       data["fpje"],
		Htfj:       data["htfj"],
		Htfl:       data["htfl"],
		Htnr:       data["htnr"],
	}
}
func NewContractBean(data map[string]string) ContractBean {
	return ContractBean{
		Id:       data["id"],
		ParentId: data["parent_id"],
		Htlx:     data["htlx"],
		Xmmc:     data["xmmc"],
		No:       data["no"],
		Wtdw:     data["wtdw"],
		Fzr:      data["fzr"],
		Jbgk:     data["jbgk"],
		Sf:       data["sf"],
		Dq:       data["dq"],
		Bz:       data["bz"],
		Zxdw:     data["zxdw"],
		Tze:      data["tze"],
		Zxqk:     data["zxqk"],
		Htje:     data["htje"],
		Xz:       data["xz"],
		Gznr:     data["gznr"],
		Wcqk:     data["wcqk"],
		Sbqk:     data["sbqk"],
		Xxf:      data["xxf"],
		Wcrq:     data["wcrq"],
		Qsrq:     data["qsrq"],
		Qdrq:     data["qdrq"],
		Djrq:     data["djrq"],
		Htfj:     data["htfj"],
		Jsje:     data["jsje"],
	}
}

type ContractTypeBean struct {
	Id       string `json:"id"`
	TypeName string `json:"type_name"`
}

func NewContractTypeBean(data map[string]string) ContractTypeBean {
	return ContractTypeBean{
		Id:       data["id"],
		TypeName: data["type_name"],
	}
}
func ContractCreate(parent_id, htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, djrq, htfj, qdrq, jsje string) error {
	stmtIn, err := dbConn.Prepare("INSERT INTO table_contract (jsje,parent_id,htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, djrq,htfj, qdrq)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,FROM_UNIXTIME(?))")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(jsje, parent_id, htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, djrq, htfj, qdrq)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	//创建年份
	stmtIn, err = dbConn.Prepare(`REPLACE INTO table_contract_year (htlx,year_name)VALUES(?,?)`)
	if err != nil {
		return err
	}
	timeYear, err := strconv.ParseInt(djrq, 10, 64)
	if err != nil {
		return err
	}
	tm := time.Unix(timeYear, 0)
	_, err = stmtIn.Exec("类型1", tm.Format("2006"))
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//修改合同
func ContractUpdate(id, htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, qdrq, htfj, djrq, isModifyAttachment, jsje string) error {
	if isModifyAttachment == "1" {
		stmtIn, err := dbConn.Prepare(`UPDATE table_contract set jsje=?,htlx=?, xmmc=?, no=?, wtdw=?, fzr=?, jbgk=?, sf=?, dq=?, bz=?, zxdw=?, tze=?, zxqk=?, htje=?, xz=?, gznr=?, wcqk=?, sbqk=?, xxf=?, wcrq=?, qsrq=?, djrq=?, qdrq=FROM_UNIXTIME(?) where id=?`)
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(jsje, htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, djrq, qdrq, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	} else if isModifyAttachment == "2" {
		stmtIn, err := dbConn.Prepare(`UPDATE table_contract set htfj=? where id=?`)
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(htfj, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	} else {
		stmtIn, err := dbConn.Prepare(`UPDATE table_contract set jsje=?,htlx=?, xmmc=?, no=?, wtdw=?, fzr=?, jbgk=?, sf=?, dq=?, bz=?, zxdw=?, tze=?, zxqk=?, htje=?, xz=?, gznr=?, wcqk=?, sbqk=?, xxf=?, wcrq=?, qsrq=?, djrq=?, htfj=?,qdrq=FROM_UNIXTIME(?) where id=?`)
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(jsje, htlx, xmmc, no, wtdw, fzr, jbgk, sf, dq, bz, zxdw, tze, zxqk, htje, xz, gznr, wcqk, sbqk, xxf, wcrq, qsrq, djrq, htfj, qdrq, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	}

}

//删除合同
func ContractDelete(id string) error {
	if len(id) == 0 {
		return bean.NewErrorMessage("ID不能为空")
	}
	stmtIn, err := dbConn.Prepare("DELETE FROM table_contract WHERE id=?")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(id)
	stmtIn.Close()
	stmtIn, err = dbConn.Prepare("DELETE FROM table_contract_additional WHERE contract_id=?")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(id)
	stmtIn.Close()
	beans, err := ContractSelectChildById(id)
	if err != nil {
		return err
	}
	for _, v := range beans {
		err := ContractDelete(v.Id)
		if err != nil {
			return err
		}
	}
	return nil
}

//根据id查询子合同合同
func ContractSelectChildById(contract_id string) ([]ContractBean, error) {
	var contractBeans = make([]ContractBean, 0)
	if len(contract_id) == 0 {
		return contractBeans, bean.NewErrorMessage("查询ID不能为空")
	}
	stmtOut, err := dbConn.Prepare(`SELECT * 
			, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
			 FROM table_contract WHERE  parent_id = ?`)
	if err != nil {
		return contractBeans, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(contract_id)
	if err != nil {
		return contractBeans, err
	}
	defer rows.Close()

	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractBeans, err
		}
		contractBean := NewContractBean(mapStrings)
		beans, _ := ContractAdditionalSelect(contractBean.Id)
		contractBean.Additional = beans
		contractBeans = append(contractBeans, contractBean)
	}
	return contractBeans, nil
}

//根据编号查询合同
func ContractSelectByNo(id string) (ContractBean, error) {
	var contract ContractBean
	if len(id) == 0 {
		return contract, bean.NewErrorMessage("ID不能为空")
	}
	stmtOut, err := dbConn.Prepare(`SELECT * 
			, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
			 FROM table_contract WHERE id = ?`)
	if err != nil {
		return contract, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(id)
	if err != nil {
		return contract, err
	}
	defer rows.Close()
	if rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contract, err
		}
		contract = NewContractBean(mapStrings)
		beans, err := ContractAdditionalSelect(contract.Id)
		if err != nil {
			return contract, err
		}
		contract.Additional = beans
	}
	return contract, nil
}

//根据模糊查询合同
func ContractSelectByVague(vague string) ([]ContractBean, error) {
	var contractBeans = make([]ContractBean, 0)
	if len(vague) == 0 {
		return contractBeans, bean.NewErrorMessage("查询内容不能为空")
	}
	rows, err := dbConn.Query(`SELECT * 
			, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
			 FROM table_contract WHERE concat(
			 htlx,xmmc,no,wtdw,fzr
			 ,qsrq,qdrq,jbgk,sf
			 ,dq,bz,zxdw
			 ,tze,wcrq,djrq
			 ,zxqk,htje,xz
			 ,gznr,wcqk,sbqk
			 ,xxf,htfj
			 )  like CONCAT('%',?,'%')`, vague)
	if err != nil {
		return contractBeans, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractBeans, err
		}
		contractBean := NewContractBean(mapStrings)
		beans, _ := ContractAdditionalSelect(contractBean.Id)
		contractBean.Additional = beans
		contractBeans = append(contractBeans, contractBean)
	}
	return contractBeans, nil
}

//根据时间查询合同
func ContractSelectByTime(htlx, startTime, endTime string) ([]ContractBean, error) {
	var contractBeans = make([]ContractBean, 0)
	//if len(startTime) == 0 {
	//	return contractBeans, bean.NewErrorMessage("开始时间不能为空")
	//}
	//if len(endTime) == 0 {
	//	return contractBeans, bean.NewErrorMessage("结束时间不能为空")
	//}

	s := ""
	var rows *sql.Rows
	isWhere := ""
	isAnd := ""
	isHtlx := ""
	isDate := ""
	isTime := len(startTime) != 0 && len(startTime) != 0
	if len(htlx) != 0 {
		isWhere = "where"
		isHtlx = "htlx='" + htlx + "'"
		if isTime {
			isAnd = "and"
			isDate = "date_format(qdrq,'%Y-%m-%d') between '" + startTime + "'  and  '" + endTime + "'"
		}
	} else {
		if isTime {
			isWhere = "where"
			isDate = "date_format(qdrq,'%Y-%m-%d') between '" + startTime + "'  and  '" + endTime + "'"
		}
	}
	//if len(htlx) == 0 && len(startTime) == 0 || len(startTime) == 0 {
	//
	//} else {
	//	isWhere = "where"
	//	isHtlx = "htlx="+htlx
	//	if len(startTime) != 0 && len(startTime) != 0 {
	//		isAnd = "and"
	//		isDate = "date_format(qdrq,'%Y-%m-%d') between " + startTime+"  and  "+endTime
	//	}
	//}
	s = fmt.Sprintf(`SELECT *, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
			 FROM table_contract %s  %s  %s %s order by qdrq desc`, isWhere, isHtlx, isAnd, isDate)
	rows, err = dbConn.Query(s)
	if err != nil {
		return contractBeans, err
	}
	defer rows.Close()

	//if len(startTime) == 0 || len(endTime) == 0 {
	//	rows, err = dbConn.Query(`SELECT *, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
	//		 FROM table_contract where date_format(qdrq,'%Y-%m-%d') between ? and ? order by qdrq desc`, startTime, endTime)
	//	if err != nil {
	//		return contractBeans, err
	//	}
	//	defer rows.Close()
	//}
	//if len(htlx) == 0 {
	//	s = `SELECT *, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
	//		 FROM table_contract where date_format(qdrq,'%Y-%m-%d') between ? and ? order by qdrq desc`
	//	stmtOut, err := dbConn.Prepare(s)
	//	if err != nil {
	//		return contractBeans, err
	//	}
	//	defer stmtOut.Close()
	//	rows, err = stmtOut.Query(startTime, endTime)
	//	if err != nil {
	//		return contractBeans, err
	//	}
	//	defer rows.Close()
	//} else {
	//	s = `SELECT *, UNIX_TIMESTAMP(table_contract.qdrq) as qdrq
	//		 FROM table_contract where  htlx=? and date_format(qdrq,'%Y-%m-%d') between ? and ? order by qdrq desc`
	//	stmtOut, err := dbConn.Prepare(s)
	//	if err != nil {
	//		return contractBeans, err
	//	}
	//	defer stmtOut.Close()
	//	rows, err = stmtOut.Query(htlx, startTime, endTime)
	//	if err != nil {
	//		return contractBeans, err
	//	}
	//	defer rows.Close()
	//}

	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractBeans, err
		}
		contractBean := NewContractBean(mapStrings)
		beans, _ := ContractAdditionalSelect(contractBean.Id)
		contractBean.Additional = beans
		contractBeans = append(contractBeans, contractBean)
	}
	return contractBeans, err
}

//添加合同扩展的信息
func ContractAdditionalAdd(contract_id, lx, jbr, nr, htmc, wxdw, fpje, fsrq, htfj, htfl, htnr string) (AdditionalBean, error) {
	var additionalBean AdditionalBean
	stmtIn, err := dbConn.Prepare("INSERT INTO table_contract_additional (contract_id, lx, jbr, nr, htmc, wxdw,fpje, fsrq,htfj ,htfl ,htnr)VALUES(?,?,?,?,?,?,?,?,?,?,?)")
	if err != nil {
		return additionalBean, err
	}
	result, err := stmtIn.Exec(contract_id, lx, jbr, nr, htmc, wxdw, fpje, fsrq, htfj, htfl, htnr)
	if err != nil {
		return additionalBean, err
	}
	_ = stmtIn.Close()
	i, err := result.LastInsertId()
	if err != nil {
		return additionalBean, err
	}
	return ContractAdditionalSelectById(fmt.Sprintf("%v", i))
}

//删除合同扩展的信息
func ContractAdditionalDelete(id string) error {
	stmtIn, err := dbConn.Prepare("DELETE FROM table_contract_additional WHERE id=?")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(id)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//修改合同扩展的信息
func ContractAdditionalUpdate(fpje string, id string, lx, jbr, nr, htmc, wxdw, htfj, htfl, htnr, fsrq, isModifyAttachment string) error {
	if isModifyAttachment == "1" {
		stmtIn, err := dbConn.Prepare("UPDATE table_contract_additional set fpje=?,lx=?,jbr=?,nr=?, htmc=?, wxdw=?, fsrq=? ,htfl=? ,htnr=? WHERE id=?")
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(fpje, lx, jbr, nr, htmc, wxdw, fsrq, htfl, htnr, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	} else if isModifyAttachment == "2" {
		stmtIn, err := dbConn.Prepare("UPDATE table_contract_additional set htfj=? WHERE id=?")
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(htfj, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	} else {
		stmtIn, err := dbConn.Prepare("UPDATE table_contract_additional set fpje=?,lx=?,jbr=?,nr=?, htmc=?, wxdw=?, fsrq=? ,htfj=?,htfl=? ,htnr=? WHERE id=?")
		if err != nil {
			return err
		}
		_, err = stmtIn.Exec(fpje, lx, jbr, nr, htmc, wxdw, fsrq, htfj, htfl, htnr, id)
		if err != nil {
			return err
		}
		_ = stmtIn.Close()
		return nil
	}

}

//根据查询合同附加信息
func ContractAdditionalSelect(contract_id string) ([]AdditionalBean, error) {
	var additionalBeans = make([]AdditionalBean, 0)
	stmtOut, err := dbConn.Prepare(`SELECT * 
			 FROM table_contract_additional where  contract_id=?  order by fsrq desc`)
	if err != nil {
		return additionalBeans, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(contract_id)
	if err != nil {
		return additionalBeans, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return additionalBeans, err
		}
		additionalBean := NewAdditionalBean(mapStrings)
		additionalBeans = append(additionalBeans, additionalBean)
	}
	return additionalBeans, err
}

//根据附加信息id 查询 合同附加信息
func ContractAdditionalSelectById(additional_id string) (AdditionalBean, error) {
	var additionalBean AdditionalBean
	stmtOut, err := dbConn.Prepare(`SELECT * 
			 FROM table_contract_additional where  id=?  order by fsrq desc`)
	if err != nil {
		return additionalBean, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(additional_id)
	if err != nil {
		return additionalBean, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return additionalBean, err
		}
		additionalBean = NewAdditionalBean(mapStrings)
	}
	return additionalBean, err
}

//创建合同类型
func ContractTypeCreate(type_name string) error {
	typeBean, err := ContractTypeSelect(type_name)
	if err != nil {
		return err
	}
	if len(typeBean.TypeName) > 0 {
		return bean.NewErrorMessage("合同类型已经存在了")
	}
	stmtIn, err := dbConn.Prepare("INSERT INTO table_contract_type (type_name)VALUES(?)")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(type_name)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//创建工作类型
func WorkTypeCreate(type_name string) error {
	typeBean, err := WorkTypeSelect(type_name)
	if err != nil {
		return err
	}
	if len(typeBean.TypeName) > 0 {
		return bean.NewErrorMessage("工作类型已经存在了")
	}
	stmtIn, err := dbConn.Prepare("INSERT INTO table_work_type (type_name)VALUES(?)")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(type_name)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//删除合同类型
func ContractTypeDelete(type_name string) error {
	stmtOut, err := dbConn.Prepare(`SELECT * FROM table_contract where  htlx=?`)
	if err != nil {
		return err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(type_name)
	if err != nil {
		return err
	}
	defer rows.Close()
	if rows.Next() {
		return bean.NewErrorMessage("此合同类型存在合同,不能删除!")
	}
	stmtIn, err := dbConn.Prepare("DELETE FROM table_contract_type WHERE type_name=?")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(type_name)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//删除工作类型
func WorkTypeDelete(type_name string) error {
	stmtIn, err := dbConn.Prepare("DELETE FROM table_work_type WHERE type_name=?")
	if err != nil {
		return err
	}
	_, err = stmtIn.Exec(type_name)
	if err != nil {
		return err
	}
	_ = stmtIn.Close()
	return nil
}

//查询合同类型
func ContractTypeSelect(type_name string) (ContractTypeBean, error) {
	var contractTypeBean ContractTypeBean
	stmtOut, err := dbConn.Prepare("SELECT * FROM table_contract_type where type_name=?")
	if err != nil {
		return contractTypeBean, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(type_name)
	if err != nil {
		return contractTypeBean, err
	}
	defer rows.Close()
	if rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractTypeBean, err
		}
		contractTypeBean = NewContractTypeBean(mapStrings)
	}
	return contractTypeBean, nil
}

//查询工作类型
func WorkTypeSelect(type_name string) (ContractTypeBean, error) {
	var contractTypeBean ContractTypeBean
	stmtOut, err := dbConn.Prepare("SELECT * FROM table_work_type where type_name=?")
	if err != nil {
		return contractTypeBean, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query(type_name)
	if err != nil {
		return contractTypeBean, err
	}
	defer rows.Close()
	if rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractTypeBean, err
		}
		contractTypeBean = NewContractTypeBean(mapStrings)
	}
	return contractTypeBean, nil
}

//查询合同类型
func ContractTypeSelectAll() ([]ContractTypeBean, error) {
	var contractTypeBeans = make([]ContractTypeBean, 0)
	stmtOut, err := dbConn.Prepare("SELECT * FROM table_contract_type")
	if err != nil {
		return contractTypeBeans, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query()
	if err != nil {
		return contractTypeBeans, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractTypeBeans, err
		}
		contractTypeBean := NewContractTypeBean(mapStrings)
		contractTypeBeans = append(contractTypeBeans, contractTypeBean)
	}
	return contractTypeBeans, nil
}

//查询合同类型
func WorkTypeSelectAll() ([]ContractTypeBean, error) {
	var contractTypeBeans = make([]ContractTypeBean, 0)
	stmtOut, err := dbConn.Prepare("SELECT * FROM table_work_type")
	if err != nil {
		return contractTypeBeans, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query()
	if err != nil {
		return contractTypeBeans, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return contractTypeBeans, err
		}
		contractTypeBean := NewContractTypeBean(mapStrings)
		contractTypeBeans = append(contractTypeBeans, contractTypeBean)
	}
	return contractTypeBeans, nil
}

//查询时间
func ContractYearSelectAll(htlx string) ([]string, error) {
	var years = make([]string, 0)
	stmtOut, err := dbConn.Prepare("SELECT * FROM table_contract_year")
	if err != nil {
		return years, err
	}
	defer stmtOut.Close()
	rows, err := stmtOut.Query()
	if err != nil {
		return years, err
	}
	defer rows.Close()
	for rows.Next() {
		mapStrings, err := dbutils.GetRowsMap(rows)
		if err != nil {
			return years, err
		}
		years = append(years, mapStrings["year_name"])
	}
	return years, nil
}
